package com.ai.study.dashscope.controller.chatClient;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author chenwei
 * @Date 2025/6/29 19:19
 */
@RestController
@RequestMapping("/dashscope/defaultSystem")
@RequiredArgsConstructor
@Tag(name = "defaultSystem测试")
public class DefaultSystemController {

    @Autowired
    @Qualifier("dashScopeChatClientDefaultSystem")
    private final ChatClient dashScopeChatClientDefaultSystem;

    /**
     * 还可以将System提示词里面的字段进行替换
     */
    @GetMapping("/chat")
    public Map<String, String> completion(
            @RequestParam(value = "message", defaultValue = "Tell me a joke") String message,
            String voice) {
        return Map.of(
                "completion",
                dashScopeChatClientDefaultSystem.prompt()
                        .system(sp -> sp.param("voice", voice))
                        .user(message)
                        .call()
                        .content());
    }
}
